using System;
using Velocity4Net.Ctx;
using Velocity4Net.Runtime.Parse.AST;

namespace Velocity4Net.Runtime.Directives
{
    /// <summary> A very simple directive that leverages the Node.literal()
    /// to grab the literal rendition of a node. We basically
    /// grab the literal value on init(), then repeatedly use
    /// that during render().
    /// *
    /// </summary>
    /// <author> <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    /// </author>
    /// <version> $Id: Literal.cs,v 1.3 2003/10/27 13:54:10 corts Exp $
    ///
    /// </version>
    public class Literal : Directive
    {
        public override System.String Name
        {
            get
            {
                return "literal";
            }
            set
            {
                throw new NotSupportedException();
            }
        }
        public override int Type
        {
            get
            {
                return Velocity4Net.Runtime.Directives.DirectiveConstants_Fields.BLOCK;
            }

        }
        internal System.String literalText;

        /// <summary> Return name of this directive.
        /// </summary>

        /// <summary> Return type of this directive.
        /// </summary>

        /// <summary> Store the literal rendition of a node using
        /// the Node.literal().
        /// </summary>
        public override void Init(RuntimeServices rs, InternalContextAdapter context, INode node)
        {
            base.Init(rs, context, node);

            literalText = node.jjtGetChild(0).Literal();
        }

        /// <summary> Throw the literal rendition of the block between
        /// #literal()/#end into the writer.
        /// </summary>
        public override bool Render(InternalContextAdapter context, System.IO.TextWriter writer, INode node)
        {
            writer.Write(literalText);
            return true;
        }
    }
}
